package com.master.controller.repair;

import com.master.common.utils.EmptyUtil;
import com.master.common.utils.Result;
import com.master.constant.model.CsRepair;
import com.master.service.repair.CsRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Heath.Que
 * @version 1.0
 * @classname SysRepairServiceImpl
 * @description TODO
 * @Date 2021/5/31 13:57
 **/
@RestController(value = "/repair")
@RequestMapping(value = "/neighbourhood/repair")
public class SysRepairController {


    @Autowired
    private CsRepairService csRepairService;

    /**
     * @Description: 条件查询维修单信息
     * @Parameter: [csRepairVO]
     * @Return: com.master.common.utils.Result
     * @author: Heath.Que
     * @Date: 2021/6/2
     **/
    @PostMapping(value = "/getRepairsByCondition")
    public Result getRepairsByCondition(@RequestBody CsRepairVO csRepairVO){
        Map<String, Object> searchCondition = csRepairVO.getSearchCondition();
        //按限制条件搜索
        List<Map<String, Object>> repairs = csRepairService.getRepairsByCondition(searchCondition);
        return Result.success(repairs);
    }

    /**
     * @Description: 条件查询维修单信息
     * @Parameter: [csRepairVO]
     * @Return: com.master.common.utils.Result
     * @author: Heath.Que
     * @Date: 2021/6/2
     **/
    @PostMapping(value = "/addRepairs")
    public Result addRepairs(@RequestBody CsRepairVO csRepairVO){
        if (EmptyUtil.isEmpty(csRepairVO)){
            return Result.fail("传入参数为空！");
        }
        //传入新增维修单数据
        List<CsRepair> repairs = new ArrayList<>();
        repairs.add(csRepairVO.getRepair());
        boolean mark = csRepairService.addRepairs(repairs);

        if (mark){
            return Result.success();
        }else {
            return Result.fail();
        }
    }

    /**
     * @Description: 条件查询维修单信息
     * @Parameter: [csRepairVO]
     * @Return: com.master.common.utils.Result
     * @author: Heath.Que
     * @Date: 2021/6/2
     **/
    @PostMapping(value = "/modifyRepairs")
    public Result modifyRepairs(@RequestBody CsRepairVO csRepairVO){
        if (EmptyUtil.isEmpty(csRepairVO)){
            return Result.fail("传入参数为空！");
        }
        //传入新增维修单数据
        boolean mark = csRepairService.modifyRepairs(csRepairVO.getRepair());

        if (mark){
            return Result.success();
        }else {
            return Result.fail();
        }
    }

    /**
     * @Description: 维修单分派
     * @Parameter: [csRepairVO]
     * @Return: com.master.common.utils.Result
     * @author: Heath.Que
     * @Date: 2021/6/3
     **/
    @PostMapping(value = "/allocateRepairs")
    public Result allocateRepairs(@RequestBody CsRepairVO csRepairVO){
        if (EmptyUtil.isEmpty(csRepairVO)) {
            return Result.fail("传入参数为空！");
        }

        boolean mark = csRepairService.allocateRepairs(csRepairVO);
        if (mark){
            return Result.success();
        }else {
            return Result.fail();
        }
    }

    /**
     * @Description: 维修单处理汇报
     * @Parameter: [csRepairVO]
     * @Return: com.master.common.utils.Result
     * @author: Heath.Que
     * @Date: 2021/6/3
     **/
    @PostMapping(value = "/dealRepair")
    public Result dealRepair(@RequestBody CsRepairVO csRepairVO){
        if (EmptyUtil.isEmpty(csRepairVO.getRepair())){
            return Result.fail("传入信息为空!");
        }
        boolean mark = csRepairService.modifyRepairs(csRepairVO.getRepair());
        if (mark){
            return Result.success();
        }else {
            return Result.fail();
        }
    }

}
